﻿import { Component, Injector, ViewChild , Input} from '@angular/core';
import { appModuleAnimation } from '@shared/animations/routerTransition';
import { AppComponentBase } from '@shared/common/app-component-base';
import { finalize } from 'rxjs/operators';
import { Tab } from './tab.model';
import { Paginator } from 'primeng/components/paginator/paginator';
import { Table } from 'primeng/components/table/table';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { AuditAuthorityTabEditComponent } from './audit-authority_tab_edit.component'
import { RequirementItemDto,StandardDetailType,RoleUserServiceProxy,CheckerRoleEnum,RoleUserDto } from '@shared/service-proxies/service-proxies';

@Component({
    selector: 'auditAuthorityTabComponent',
    templateUrl: './audit-authority_tab.component.html',
    styleUrls: ['./audit-authority_tab.component.less'],
    animations: [appModuleAnimation()]
})
export class AuditAuthorityTabComponent extends AppComponentBase{
    @ViewChild('auditAuthorityTabEditComponent') auditAuthorityTabEditComponent: AuditAuthorityTabEditComponent;
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;
    tabs: Array<Tab>;
    tabObject:{
        filterText:""
    };
    loading = false;
    caches: any = null;
    logs: any = '';
    filterText = '';

    active =false;
    hidden=true;
    title:"hello";
    @Input() index: number;
    

    constructor(
        injector: Injector,
        private _roleUserServiceProxy:RoleUserServiceProxy) {
        super(injector);
        this.active = false;
    }
    getRoleName(code): string {
        return CheckerRoleEnum[code];
    }
    addTab(requirementItemDto: RequirementItemDto): void {
        this.active = true;
    }
    clearTab(): void {
    }
    createRequirementItem(event?: LazyLoadEvent):void{
    }
    
    /**
    * 弹出添加需求详细页面
    * 弹出编辑需求详细页面
    * @param requirementItemDto 
    */
    createOrEditRequirementItem(record):void{
        this.auditAuthorityTabEditComponent.show(record,this.index);
    }

    createOrEditRequirementPackage(requirementItemDto: RequirementItemDto): void {

    }
    deleteRoleUserById(roleUserDto :RoleUserDto): void {
        this.message.confirm(
            '该记录将被删除',
            this.l('AreYouSure'),
            (isConfirmed) => {
                if (isConfirmed) {
                    this._roleUserServiceProxy.deleteUserOfRole(roleUserDto.id)
                    .pipe(finalize(() => { this.getRequirementItems();}))
                    .subscribe(() => {
                        this.notify.info(this.l('DeletedSuccessfully'));
                        this.getRequirementItems();
                    });
                }
            }
        );
    }
    getRequirements( tab:Tab,event?: LazyLoadEvent) {
        this.primengTableHelper.showLoadingIndicator();
    }   
    getStandarType(standardType:string):string{
        return StandardDetailType[standardType];
    } 
    /**
    * 检索需求详细
    * @param requirementItemDto 
    */
    getRequirementItems(event?: LazyLoadEvent) {
        if (this.primengTableHelper.shouldResetPaging(event)) {
            this.paginator.changePage(0);
            return;
        }
        this.primengTableHelper.showLoadingIndicator();
        this._roleUserServiceProxy.getUsersByRole(this.index)//CheckerRoleEnum.车间审批领导
            .pipe(finalize(() => this.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
                this.primengTableHelper.totalRecordsCount = result.length;
                this.primengTableHelper.records = result;
                this.primengTableHelper.hideLoadingIndicator();
            });
    }

    reloadPage():void {
        
    }

    downloadWebLogs = function () {
        const self = this;
        self._webLogService.downloadWebLogs().subscribe((result) => {
            self._fileDownloadService.downloadTempFile(result);
        });
    };

    onResize(event): void {
    }
}
